package com.fenghongzhang.two;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;

import java.util.List;

public class MyAdapter extends BaseAdapter {

    private static final String TAG = "MyAdapter";
    private Context context;
    private List<String> list;

    public MyAdapter(Context context, List<String> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView == null){
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.lvlayout, null);

            viewHolder.imageView = convertView.findViewById(R.id.lv_img);
            convertView.setTag(viewHolder);
        }

        viewHolder  = (ViewHolder) convertView.getTag();

        Log.i(TAG, "getView: "+list.get(position));
        Glide.with(context).load(list.get(position)).apply(new RequestOptions().circleCrop()).into(viewHolder.imageView);



//        Glide.with(context).load("http://img5.imgtn.bdimg.com/it/u=1831321739,3083785234&fm=26&gp=0.jpg").into(viewHolder.imageView);
//        viewHolder.imageView.setImageResource(R.mipmap.ic_launcher); //本身的listview嫩头不鞥用.
        return convertView;
    }

    class ViewHolder{
        ImageView imageView;
    }
}
